// pages/Details/Details.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     id: null,
     info: null,
    loginName: app.globalData.loginName,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      id: options.id,
      loginName: app.globalData.loginName,
    })
    this.getObjInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getObjInfo: function(){
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + '/wx/administrative/apply/edit', //接口地址
      data: {
        loginName: app.globalData.loginName,
        id: that.data.id,
      },
      success: function (res) {
        console.log("数据详情=", res)
        that.setData({
          //array2: res.data.data,
          info: res.data.data
        })
        console.log(that.data.info)
      }
    })
  },

  //同意
  agree: function () {
    wx.showToast({
      icon: 'loading',
      title: '提交中',
      mask: true
    })
    var that = this;
    var variable = [];
    variable.push("taskResult:true")

        wx.request({
        url: app.globalData.apiUrl + '/wx/administrative/apply/completeTask', //接口地址
          data: {
            loginName: app.globalData.loginName,
            applyId: that.data.id,
            taskId: that.data.info.nowTask.taskid,
            variable: variable.toString()
          },
          success: function (res) {
            console.log("数据详情=", res)
            //wx.hideToast();
            if (res.data.code == 0) {

              //添加车牌号，修改用车状态--占用
              wx.request({
                url: app.globalData.apiUrl + '/wx/administrative/apply/updateCarStatue', //接口地址
                data: {
                  Id: that.data.id,
                  disabled: true
                },
                success: function (res) {
                  if (res.data.code == 0) {
                    that.getObjInfo();
                    wx.showToast({
                      title: '操作成功！',
                      icon: 'success',
                      duration: 2000
                    })
                  } else {
                    wx.showToast({
                      title: res.data.msg,
                      icon: 'none',
                      duration: 2000
                    })
                  }
                }
              })


             
            }else{
               wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              })
            }
          }
        })
  },

  //驳回
  reject: function () {
    wx.showToast({
      icon: 'loading',
      title: '提交中',
      mask: true
    })
    var that = this;
    var variable = [];
    variable.push("taskResult:rollback");

    wx.request({
      url: app.globalData.apiUrl + '/wx/administrative/apply/completeTask', //接口地址
      data: {
        loginName: app.globalData.loginName,
        applyId: that.data.id,
        taskId: that.data.info.nowTask.taskid,
        variable: variable.toString()
      },
      success: function (res) {
        console.log("数据详情=", res)
        wx.hideToast();
        if (res.data.code == 0) {
          that.getObjInfo();
          wx.showToast({
            title: '操作成功！',
            icon: 'success',
            duration: 2000
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },

  //继续申请
  continueTask: function () {
    wx.showToast({
      icon: 'loading',
      title: '提交中',
      mask: true
    })
    var that = this;
    var variable = [];
    variable.push("taskResult:continue")

    wx.request({
      url: app.globalData.apiUrl + '/wx/administrative/apply/completeTask', //接口地址
      data: {
        loginName: app.globalData.loginName,
        applyId: that.data.id,
        taskId: that.data.info.nowTask.taskid,
        variable: variable.toString()
      },
      success: function (res) {
        console.log("数据详情=", res)
        wx.hideToast();
        if (res.data.code == 0) {
          that.getObjInfo();
          wx.showToast({
            title: '操作成功！',
            icon: 'success',
            duration: 2000
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },

  //终止申请
  terminateTask: function () {
    wx.showToast({
      icon: 'loading',
      title: '提交中',
      mask: true
    })
    var that = this;
    var variable = [];
    variable.push("taskResult:terminate")

    wx.request({
      url: app.globalData.apiUrl + '/wx/administrative/apply/completeTask', //接口地址
      data: {
        loginName: app.globalData.loginName,
        applyId: that.data.id,
        taskId: that.data.info.nowTask.taskid,
        variable: variable.toString()
      },
      success: function (res) {
        console.log("数据详情=", res)
        wx.hideToast();
        if (res.data.code == 0) {
          that.getObjInfo();
          wx.showToast({
            title: '操作成功！',
            icon: 'success',
            duration: 2000
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },

})

